' 使用方法使用方法
' PowerDesigner->Tools->Execute Commands->Edit/Run Scripts
' 可以保存该脚本为:comment2name.vbs
' 用于数据库sql转pdm
' 只会作用于当前model下当前的diagram

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

' the current model
Dim mdl 
' the current diagram
Dim Diagram

' get the current active model 
Set mdl = ActiveModel
If (mdl Is Nothing) Then
    MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
    MsgBox "The current model is not an Physical Data model. "
Else
	Set Diagram = ActiveDiagram
    ProcessFolder Diagram
End If

' This routine copy name into comment for each table, each column and each view 
' of the current folder 
Private Sub ProcessFolder(folder)
	Dim Symbol
    Dim Tab 'running table 
    For Each Symbol In folder.Symbols
		If Symbol.ClassKind = cls_TableSymbol Then
			Set Tab = Symbol.Object
			If Not tab.isShortcut Then
				' 如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面. 
				If Trim(tab.comment) = "" Then
					tab.comment = tab.name
				End If
				Dim col ' running column 
				For Each col In tab.columns
					' 将表注释替换为name
					If col.name = col.code Then
						col.name = col.comment
					End If
				Next
			End If
		End If
    Next
End Sub
